<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" id="username">
    <input type="text" id="password">

    <script>
        var username = document.getElementById("username");
        var password = document.getElementById("password");

        username.onkeydown = function(e){
            console.log("摁下了");
        }
        username.onkeyup = function (e) {
            console.log(e.target.value);
        }
        //onkeypress,只接受有值的键盘事件，数字字母符号为有值，其他为无值
        username.onkeypress = function (e){
            console.log("onkeypress");
        }

        //keyCode属性：唯一标识，用来识别键盘摁下了哪个键，类似于ascii码
        password.onkeyup = function(e){
            console.log(e.keyCode);
            if(e.keyCode === 13){
                console.log("开始搜索");
            }
        }
    </script>
</body>
</html>